// pages/fenshuziping/fenshuziping.js
const app = getApp()
import { addPit } from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    form: {
      sleep_time: "",
      go_sleep_time: "",
      go_up_time: "",
      deep_sleep: "",
      fei_sleep_depth: "",
      pi_sleep_depth: "",
      difficulty_sleep_time: "",
      night_festless_sleep: "",
      night_wc: "",
      breathe_difficulty: "",
      cough_num: "",
      feel_cold: "",
      feel_hot: "",
      dream_num: "",
      is_pain: "",
      other_thing: "",
      hypnotic: "",
      tired: "",
      lacking: "",
      sleep_quality: "",
      dissatisfied: ""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  // 1
  onChange1(event) {
    this.setData({
      'form.sleep_time': event.detail.value
    })
  },
  // 2
  onChange2(event) {
    this.setData({
      'form.go_sleep_time': event.detail.value
    })
  },
  // 3
  onChange3(event) {
    this.setData({
      'form.go_up_time': event.detail.value
    })
  },
  // 4
  onChange4(event) {
    this.setData({
      'form.deep_sleep': event.detail.value
    })
  },
  // 4
  onChange4(event) {
    this.setData({
      'form.deep_sleep': event.detail.value
    })
  },
  // 5
  onChange5(event) {
    this.setData({
      'form.fei_sleep_depth': event.target.dataset.text
    })
  },

  // 6
  onChange6(event) {
    this.setData({
      'form.pi_sleep_depth': event.target.dataset.text
    })
  },

  // 7
  onChange7(event) {
    this.setData({
      'form.difficulty_sleep_time': event.target.dataset.text
    })
  },
  // 8
  onChange8(event) {
    this.setData({
      'form.night_festless_sleep': event.target.dataset.text
    })
  },

  // 9
  onChange9(event) {
    this.setData({
      'form.night_wc': event.target.dataset.text
    })
  },

  // 10
  onChange10(event) {
    this.setData({
      'form.breathe_difficulty': event.target.dataset.text
    })
  },

  // 11
  onChange11(event) {
    this.setData({
      'form.cough_num': event.target.dataset.text
    })
  },

  // 12
  onChange12(event) {
    this.setData({
      'form.feel_cold': event.target.dataset.text
    })
  },

  // 13
  onChange13(event) {
    this.setData({
      'form.feel_hot': event.target.dataset.text
    })
  },

  // 14
  onChange14(event) {
    this.setData({
      'form.dream_num': event.target.dataset.text
    })
  },

  // 15
  onChange15(event) {
    this.setData({
      'form.is_pain': event.target.dataset.text
    })
  },

  // 16
  onChange16(event) {
    this.setData({
      'form.other_thing': event.target.dataset.text
    })
  },

  // 17
  onChange17(event) {
    this.setData({
      'form.hypnotic': event.target.dataset.text
    })
  },

  // 18
  onChange18(event) {
    this.setData({
      'form.tired': event.target.dataset.text
    })
  },

  // 19
  onChange19(event) {
    this.setData({
      'form.lacking': event.target.dataset.text
    })
  },

  // 20
  onChange20(event) {
    this.setData({
      'form.sleep_quality': event.target.dataset.text
    })
  },

  // 21
  onChange21(event) {
    this.setData({
      'form.dissatisfied': event.detail.value
    })
  },

  // 提交
  subClick() {
    let _this = this
    if (_this.data.form.sleep_time == '') {
      wx.showToast({
        title: '第一项不能为空！',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    _this.data.form.openid = app.globalData.openid
    addPit(_this.data.form).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 1500
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 1500)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})